{% extends "base.html" %}
{% load i18n %}
{% load promgen %}

{% block content %}

<div class="page-header promgen-flex-space-between-center" v-pre>
  <div>
    <h1>
      Farm: {{ farm.name }} ({{ farm.source }})
    </h1>
  </div>
  {% if farm.editable %}
    <div>
      <a href="{% url 'farm-update' farm.id %}" class="btn btn-warning btn-sm">{% translate "Edit Farm" %}</a>
      <form
        method="post"
        action="{% url 'farm-delete' farm.id %}"
        onsubmit="return confirm('{% trans 'Are you sure you want to delete this farm? This action is permanent and cannot be undone.' %}')"
        style="display: inline"
      >
        {% csrf_token %}
        <button class="btn btn-danger btn-sm">{% trans "Delete Farm" %}</button>
      </form>
    </div>
  {% endif %}
</div>

{% breadcrumb farm %}

<div v-pre>

<div class="panel panel-default">
  <div class="panel-heading">Hosts</div>
  <table class="table">
  {% for host in farm.host_set.all %}
    <tr>
      <td><a href="{% url 'host-detail' host.name %}">{{ host.name }}</a></td>
      {% if farm.editable %}
      <td style="width: 0; min-width: fit-content;">
        <form method="post" action="{% url 'host-delete' host.id %}" onsubmit="return confirm('Really delete this host?');">
          {% csrf_token %}
        <button name="delete" type="submit" class="btn btn-danger btn-sm">Delete</button>
        </form>
      </td>
      {% endif %}
    </tr>
  {% endfor %}
  </table>

{% if farm.editable %}
  <div class="panel-footer">
    <a href="{% url 'hosts-add' farm.id %}" class="btn btn-primary">{% trans "Register Hosts" %}</a>
  </div>
{% endif %}
</div>

</div>

{% endblock %}
